package com.gongye.courseselectionsystem.controller;

import com.gongye.courseselectionsystem.constants.ResultCodeEnum;
import com.gongye.courseselectionsystem.pojo.vo.ResultList;
import com.gongye.courseselectionsystem.service.UpdateCourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author baorongchuan
 */

@Slf4j
@RestController
@Api(tags = "更新已选择课程接口")
@RequestMapping("/update")
public class UpdateCourseController {
    @Resource
    private UpdateCourseService updateCourseService;

    @ApiImplicitParams({@ApiImplicitParam(name = "studentNumber", value = "学生学号", required = true, paramType = "update"),
            @ApiImplicitParam(name = "oldTeacherJobNumber", value = "已选择的教师工号", required = true, paramType = "update"),
            @ApiImplicitParam(name = "newTeacherJobNumber", value = "要修改的教师工号", required = true, paramType = "update"),
            @ApiImplicitParam(name = "newCourseNumber", value = "要修改的教师课程标号", required = true, paramType = "update")
    })
    @ApiOperation(value = "修改选课接口", produces = MediaType.APPLICATION_JSON_VALUE)
    @GetMapping(value = "/course", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResultList updateCourse(@RequestParam("studentNumber") Integer studentNumber,
                                   @RequestParam("oldTeacherJobNumber") Integer oldTeacherJobNumber,
                                   @RequestParam("newTeacherJobNumber") Integer newTeacherJobNumber,
                                   @RequestParam("newCourseNumber") Integer newCourseNumber) {
        try {
            return updateCourseService.updateCourse(studentNumber, oldTeacherJobNumber, newTeacherJobNumber, newCourseNumber);
        } catch (Exception e) {
            return new ResultList(ResultCodeEnum.FAILED, e.getMessage());
        }
    }
}
